<template>
	<!-- 中信银行 -->
	<view>
		<view class="statusBar"></view>
		<view class="tit" v-if="list">
			<image class="titBg" src="../../static/bank-icon8.png" mode="widthFix"></image>
			<view class="kanum">{{list.balance.bankCode.replace(/^(\w{4})\w{8}(.*)$/, '$1 **** **** $2')}}</view>
			<view class="numtxt">可用余额：{{list.balance.showBalance}}</view>
			<view class="backBtn" @tap="backBtn"></view>
		</view>
		<image :style="timeimg?'position: fixed;top: 0;z-index:999':'position: static;z-index:999'" id="timeimg" style="width: 100%;" src="../../static/bank-icon13.png" mode="widthFix"></image>
		<view style="padding: 3vw;background: #f0f0f0;margin-top: -2vw;">本月</view>
		<view class="main" v-for="(item,index) in list.list" :key="index" @tap="delBtn" :data-id="item.id">
			<image v-if="item.payType!=0" src="../../static/bank-icon9.png" mode="widthFix"></image>
			<image v-if="item.payType==0" src="../../static/bank-icon10.png" mode="widthFix"></image>
			<view>
				<view style="font-size: 4.6vw;color: #333333;">{{item.payTypeStr}}</view>
				<view v-if="item.name" style="font-size: 4.6vw;color: #333333;">{{item.name}}</view>
				<view style="font-size: 4.2vw;color: #999999;">{{item.createTime}}</view>
			</view>
			<view>
				<view style="font-size: 5vw;font-weight: bold;">{{item.payType==0?'+':'-'}}{{item.showAmount}}</view>
			</view>
		</view>
		<image class="img" src="../../static/bank-icon7.png" mode="widthFix"></image>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				id:null,
				list:'',
				year:null,
				month:null,
				timeimg:false,
				timeimgtop:''
			}
		},
		onLoad(options) {
			this.id=options.id
			uni.showLoading({
			    title: '加载中'
			});
			http.get('/api/balance/getBalanceDetail',{balanceId:this.id}).then(res => {
				//console.log(res.result.balance.bankCode)
				//console.log(res.result.balance.bankCode.replace(/^(\w{4})\w{10}(.*)$/, '$1***$2'))
				if (res.code == 200 && res.result) {
					this.list=res.result
				}
				uni.hideLoading();
			})
		},
		onReady() { //页面初次渲染完毕执行
			// uni.showLoading({
			// 	title: '加载中'
			// });
			// var that=this
			// if(this.id){
			// 	http.get('/api/balance/getBalanceDetail',{balanceId:this.id}).then(res => {
			// 		//console.log(res.result.balance.bankCode)
			// 		//console.log(res.result.balance.bankCode.replace(/^(\w{4})\w{10}(.*)$/, '$1***$2'))
			// 		if (res.code == 200 && res.result) {
			// 			this.list=res.result
			// 			// if(this.list){
			// 			// 	setTimeout(function() {
			// 			// 		that.getInfo()
			// 			// 	}, 50);
			// 			// }else{
			// 			// 	console.log('asd')
			// 			// }
			// 		}
			// 		uni.hideLoading();
			// 	})
			// }
			
			
			
		},
		onShow() {
			
		},
		methods: {
			getInfo() {
				// 注意：想要拿到元素实例，需要在实例已经挂载到页面上才可以
				const query = uni.createSelectorQuery().in(this);
				query.select('#timeimg').boundingClientRect(data => {
					console.log(data)
					console.log(data.top)
					this.timeimgtop=data.top
				}).exec();
			},
			backBtn:function(){
				uni.navigateBack({
					delta: 1
				})
			},
			delBtn:function(e){
				var that=this
				uni.showModal({
				    title: '删除',
				    content: '确定删除该数据吗？',
				    success: function (res) {
				        if (res.confirm) {
				            //console.log(e.currentTarget.dataset.id);
							uni.showLoading({
							    title: '加载中'
							});
							http.get('/api/balance/delBalanceDetail',{balanceDetailId:e.currentTarget.dataset.id}).then(res => {
								uni.showToast({
								  title: res.message,
								  icon: 'none'
								});
								if(res.code==200){
									http.get('/api/balance/getBalanceDetail',{balanceId:that.id}).then(res1 => {
										if (res1.code == 200 && res1.result) {
											that.list=res1.result
										}
									})
								}
								uni.hideLoading();
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}
		}
		// onPageScroll(Object) {
		// 	var that=this;
		// 	this.currentScroll = Object.scrollTop;
		// 	//const query = uni.createSelectorQuery().in(this);
		// 	// query.select('#timeimg').boundingClientRect(data => {
		// 	// 	console.log(data.top)
		// 	// 	//this.timeimgtop=data.top
		// 	// }).exec();
		// 	const query = uni.createSelectorQuery().in(that);
		// 	query.select('#timeimg').boundingClientRect(data => {
		// 		if(data.top<0){
		// 			that.timeimg=true
		// 			//console.log('1')
		// 		}
		// 		//console.log(Object)
		// 		console.log(that.timeimgtop)
		// 		console.log(that.currentScroll)
				
		// 		if(that.timeimgtop>=that.currentScroll){
		// 			that.timeimg=false
		// 			// console.log(Object.scrollTop)
		// 			 console.log('2')
		// 		}
		// 		//console.log(data.top)
		// 	}).exec();
		// }
	}
</script>

<style>
	page{
		color: #333333;
		font-family: 'jtfont-icon';
	}
	@font-face {
		font-family:jtfont-icon;
		src: url('~@/fonts/gsfont.otf');
	}
	.img{
		width: 20vw;
		position: fixed;
		bottom: 28vw;
		right: 0;
	}
	.statusBar{
		height: 6vw;
		background: #000000;
	}
	.tit{
		position: relative;
	}
	.titBg{
		width: 100%;
	}
	.kanum{
		position: absolute;
		top: 31vw;
		left: 35vw;
	}
	.numtxt{
		position: absolute;
		top: 56.6vw;
		right: 5.2vw;
		color: #888888;
		font-size: 3.5vw;
	}
	.backBtn{
		width: 10vw;
		height: 10vw;
		position: absolute;
		top: 2vw;
		left: 4vw;
	}
	.main{
		padding: 1.4vw 4vw 1.4vw 0;
		margin: 0 0 0 4.2vw;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #F2F2F2;
	}
	.main image{
		width: 6.8vw;
		margin-right: 1.8vw;
	}
	.main>view:nth-child(2){
		flex: 1;
		text-align: left;
	}
	.main>view:nth-child(1)>view:nth-child(2),.main>view:nth-child(2)>view:nth-child(2){
		margin-bottom: 2.2vw;
	}
</style>
